#include<iostream>
using namespace std;
class CDate
{
    private:
        int year,month,day;
    public:
        CDate(int a=0)
        {
            day=a%100;
            a=a/100;
            month=a%100;
            a=a/100;
            year=a;
        }
        operator int()
        {
            int ans=0;
            ans=year*10000+month*100+day;
            return ans;
        }
        void print()
        {
            printf("%02d年%02d月%02d日\n",year,month,day);
        }
};
int main()
{
	int t, t1, t2;
	CDate c1, c2;
	cin >> t;
	while (t--)
	{
		cin >> t1 >> t2;
		c1 = t1;
		c2 = t2;
		((c1 > c2) ? c1 : c2).print(); //日期大的输出，在代码c1 > c2中，会自动把c1和c2转换为整数进行比较
	}
	return 0;
}